package hotLeetcode;

import java.util.HashSet;

public class Test06 {


    private static int[][] board = {{1, 0, 0, 4, 0, 2}, {2, 3, 0, 0, 0, 0}, {0, 1, 0, 2, 0, 0}, {0, 0, 2, 0, 1, 0}, {0, 0, 0, 0, 4, 5}, {5, 0, 4, 4, 0, 1}};

    private static int[][] regions = {
            {1, 1, 2, 2, 3, 3},
            {1, 4, 2, 2, 3, 5},
            {6, 4, 4, 7, 7, 5},
            {6, 8, 8, 7, 9, 5},
            {6, 8, 10, 10, 9, 9},
            {11, 11, 10, 10, 10, 9}
    };

    //方法获取当前一填充的数字
    public static HashSet<Integer> get(int regionId) {
        HashSet<Integer> numbers = new HashSet<>();
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (regions[i][j] == regionId && board[i][j] != 0) {
                    numbers.add(board[i][j]);
                }
            }
        }
        return numbers;
    }

    //就是回溯求解数独
    public static boolean solve() {
        for (int row = 0; row < 6; row++) {
            for (int col = 0; col < 6; col++) {
                int num = 0;
                if (board[row][col] == 0) {
                    //找到了填充的位置 开始填充
                    board[row][col] = num;
                    num++;
                    if (solve()) return true; //递归找下一个
                    //回溯
                    board[row][col] = 0;

                }
            }
            return false;
        }
        return true;
    }






}
